package com.cntcdt.api.db.dao;

import java.util.List;

import com.cntcdt.api.db.dao.base.UpdateDeviceVersionDaoBase;
import com.cntcdt.api.db.model.UpdateDeviceVersionModel;

/**
 * 这是cdt_update_device_version的Dao实现类
 */
public class UpdateDeviceVersionDao extends UpdateDeviceVersionDaoBase {
	/**
	 * UpdateDeviceVersionDao对象
	 */
	private static UpdateDeviceVersionDao instance = new UpdateDeviceVersionDao();

	/**
	 * 默认构造方法
	 */
	private UpdateDeviceVersionDao() {
	}

	/**
	 * 获得对象实例
	 */
	public static UpdateDeviceVersionDao getInstance() {
		return instance;
	}

	public List<UpdateDeviceVersionModel> findBySortTime(int sortTime) {
		sortTime = sortTime * 20;
		String sql = "SELECT * FROM " + TABLE + " order by id desc limit ?,20";
		Object[] paramObjs = { sortTime };
		List<UpdateDeviceVersionModel> modelList = this.queryModelList(sql, paramObjs);
		return modelList;
	}

	public List<UpdateDeviceVersionModel> findBySortTimeAndUpdateType(int sortTime, int updateType) {
		sortTime = sortTime * 20;
		String sql = "SELECT * FROM " + TABLE + " where updateType = ? order by id desc limit ?,20";
		Object[] paramObjs = { updateType, sortTime };
		List<UpdateDeviceVersionModel> modelList = this.queryModelList(sql, paramObjs);
		return modelList;
	}

	public List<UpdateDeviceVersionModel> findBySortTimeAndVersion(int sortTime, String version) {
		sortTime = sortTime * 20;
		String sql = "SELECT * FROM " + TABLE + " where version = ? order by id desc limit ?,20";
		Object[] paramObjs = { version, sortTime };
		List<UpdateDeviceVersionModel> modelList = this.queryModelList(sql, paramObjs);
		return modelList;
	}

	public List<UpdateDeviceVersionModel> findBySortTimeAndSearchContent(int sortTime, String searchContent) {
		sortTime = sortTime * 20;
		String sql = "SELECT * FROM " + TABLE + " where terminal like ? order by id desc limit ?,20";
		Object[] paramObjs = { searchContent, sortTime };
		List<UpdateDeviceVersionModel> modelList = this.queryModelList(sql, paramObjs);
		return modelList;
	}

	public UpdateDeviceVersionModel findByTermianl(String termianl) {
		String sql = "SELECT * FROM " + TABLE + " WHERE terminal = ?";
		Object[] paramObjs = { termianl };
		List<UpdateDeviceVersionModel> modelList = this.queryModelList(sql, paramObjs);
		if (modelList != null && modelList.size() > 0) {
			return modelList.get(0);
		}
		return null;
	}

	public List<UpdateDeviceVersionModel> findBySortTimeAndUpdateTypeAndTerminals(int sortTime, int updateType,
			String terminals) {
		sortTime = sortTime * 20;
		String sql = "SELECT * FROM " + TABLE + " where updateType = ? and terminal in (" + terminals
				+ ") order by id desc limit ?,20";
		Object[] paramObjs = { updateType, sortTime };
		List<UpdateDeviceVersionModel> modelList = this.queryModelList(sql, paramObjs);
		return modelList;
	}

	public List<UpdateDeviceVersionModel> findBySortTimeAndVersionAndTerminals(int sortTime, String version,
			String terminals) {
		sortTime = sortTime * 20;
		String sql = "SELECT * FROM " + TABLE + " where version = ? and terminal in (" + terminals
				+ ") order by id desc limit ?,20";
		Object[] paramObjs = { version, sortTime };
		List<UpdateDeviceVersionModel> modelList = this.queryModelList(sql, paramObjs);
		return modelList;
	}

	public List<UpdateDeviceVersionModel> findBySortTimeAndSearchContentAndTerminals(int sortTime, String searchContent,
			String terminals) {
		sortTime = sortTime * 20;
		String sql = "SELECT * FROM " + TABLE + " where terminal like ? and terminal in (" + terminals
				+ ") order by id desc limit ?,20";
		Object[] paramObjs = { searchContent, sortTime };
		List<UpdateDeviceVersionModel> modelList = this.queryModelList(sql, paramObjs);
		return modelList;
	}

	public List<UpdateDeviceVersionModel> findBySortTimeAndTerminals(int sortTime, String terminals) {
		sortTime = sortTime * 20;
		String sql = "SELECT * FROM " + TABLE + " where terminal in (" + terminals
				+ ") order by id desc limit ?,20";
		Object[] paramObjs = { sortTime };
		List<UpdateDeviceVersionModel> modelList = this.queryModelList(sql, paramObjs);
		return modelList;
	}

	public List<UpdateDeviceVersionModel> findBySortTimeAndVersionAndUpdateType(int sortTime, String version,
			int updateType) {
		sortTime = sortTime * 20;
		String sql = "SELECT * FROM " + TABLE + " where version = ? and updateType = ? order by id desc limit ?,20";
		Object[] paramObjs = { version, updateType, sortTime };
		List<UpdateDeviceVersionModel> modelList = this.queryModelList(sql, paramObjs);
		return modelList;
	}

	public List<UpdateDeviceVersionModel> findBySortTimeAndVersionAndUpdateTypeAndTerminals(int sortTime,
			String version, int updateType, String terminals) {
		sortTime = sortTime * 20;
		String sql = "SELECT * FROM " + TABLE + " where version = ? and updateType = ? and terminal in (" + terminals
				+ ") order by id desc limit ?,20";
		Object[] paramObjs = { version, updateType, sortTime };
		List<UpdateDeviceVersionModel> modelList = this.queryModelList(sql, paramObjs);
		return modelList;
	}

	public List<UpdateDeviceVersionModel> findAllVersion() {
		String sql = "SELECT * FROM " + TABLE + " group by version";
		List<UpdateDeviceVersionModel> modelList = this.queryModelList(sql, null);
		return modelList;
	}

	public List<UpdateDeviceVersionModel> findAllVersion2(String terminals) {
		String sql = "SELECT * FROM " + TABLE + " where terminal in (" + terminals + ") group by version";
		List<UpdateDeviceVersionModel> modelList = this.queryModelList(sql, null);
		return modelList;
	}

	public List<UpdateDeviceVersionModel> findAllModel() {
		String sql = "SELECT * FROM " + TABLE + " where opStatus = 0";
		List<UpdateDeviceVersionModel> modelList = this.queryModelList(sql, null);
		return modelList;
	}

	public List<UpdateDeviceVersionModel> findBySortTimeNotInTerminals(int sortTime, String terminals) {
		sortTime = sortTime * 20;
		String sql = "SELECT * FROM " + TABLE + " where terminal not in (" + terminals
				+ ") order by id desc limit ?,20";
		System.out.println(sql);
		Object[] paramObjs = { sortTime };
		List<UpdateDeviceVersionModel> modelList = this.queryModelList(sql, paramObjs);
		return modelList;
	}

	public List<UpdateDeviceVersionModel> findBySortTimeAndSoftVersion(int sortTime, String softVersion) {
		sortTime = sortTime * 20;
		String sql = "SELECT * FROM " + TABLE + " where softVersion = ? order by id desc limit ?,20";
		Object[] paramObjs = { softVersion, sortTime };
		List<UpdateDeviceVersionModel> modelList = this.queryModelList(sql, paramObjs);
		return modelList;
	}

	public List<UpdateDeviceVersionModel> findBySortTimeAndSoftVersionAndTerminals(int sortTime, String softVersion,
			String terminals) {
		sortTime = sortTime * 20;
		String sql = "SELECT * FROM " + TABLE + " where softVersion = ? and terminal in (" + terminals
				+ ") order by id desc limit ?,20";
		Object[] paramObjs = { softVersion, sortTime };
		List<UpdateDeviceVersionModel> modelList = this.queryModelList(sql, paramObjs);
		return modelList;
	}

	public List<UpdateDeviceVersionModel> findBySortTimeAndVersionAndSoftVersionAndUpdateType(int sortTime,
			String version, String softVersion, int updateType) {
		sortTime = sortTime * 20;
		String sql = "SELECT * FROM " + TABLE
				+ " where version = ? and softVersion =? and updateType = ? order by id desc limit ?,20";
		Object[] paramObjs = { version, softVersion, updateType, sortTime };
		List<UpdateDeviceVersionModel> modelList = this.queryModelList(sql, paramObjs);
		return modelList;
	}

	public List<UpdateDeviceVersionModel> findBySortTimeAndSoftVersionAndSoftVersion(int sortTime, String version,
			String softVersion) {
		sortTime = sortTime * 20;
		String sql = "SELECT * FROM " + TABLE + " where version = ? and softVersion = ? order by id desc limit ?,20";
		Object[] paramObjs = { version, softVersion, sortTime };
		List<UpdateDeviceVersionModel> modelList = this.queryModelList(sql, paramObjs);
		return modelList;
	}

	public List<UpdateDeviceVersionModel> findBySortTimeAndSoftVersionAndUpdateType(int sortTime, int updateType,
			String softVersion) {
		sortTime = sortTime * 20;
		String sql = "SELECT * FROM " + TABLE + " where updateType = ? and softVersion = ? order by id desc limit ?,20";
		Object[] paramObjs = { updateType, softVersion, sortTime };
		List<UpdateDeviceVersionModel> modelList = this.queryModelList(sql, paramObjs);
		return modelList;
	}

	public List<UpdateDeviceVersionModel> findBySortTimeAndVersionAndUpdateTypeAndSoftVersionAndTerminals(int sortTime,
			String version, int updateType, String softVersion, String terminals) {
		sortTime = sortTime * 20;
		String sql = "SELECT * FROM " + TABLE
				+ " where version = ? and updateType = ? and softVersion = ? and terminal in (" + terminals
				+ ") order by id desc limit ?,20";
		Object[] paramObjs = { version, updateType, softVersion, sortTime };
		List<UpdateDeviceVersionModel> modelList = this.queryModelList(sql, paramObjs);
		return modelList;
	}

	public List<UpdateDeviceVersionModel> findBySortTimeAndVersionAndSoftVersionAndTerminals(int sortTime,
			String version, String softVersion, String terminals) {
		sortTime = sortTime * 20;
		String sql = "SELECT * FROM " + TABLE + " where version = ? and softVersion = ? and terminal in (" + terminals
				+ ") order by id desc limit ?,20";
		Object[] paramObjs = { version, softVersion, sortTime };
		List<UpdateDeviceVersionModel> modelList = this.queryModelList(sql, paramObjs);
		return modelList;
	}

	public List<UpdateDeviceVersionModel> findBySortTimeAndUpdateAndSoftVersionAndTerminals(int sortTime,
			int updateType, String softVersion, String terminals) {
		sortTime = sortTime * 20;
		String sql = "SELECT * FROM " + TABLE + " where updateType = ? and softVersion = ? and terminal in ("
				+ terminals + ") order by id desc limit ?,20";
		Object[] paramObjs = { updateType, softVersion, sortTime };
		List<UpdateDeviceVersionModel> modelList = this.queryModelList(sql, paramObjs);
		return modelList;
	}
}
